import java.util.Arrays;

public class Leetcode1605 {

    public static void main(String[] args) {
        System.out.println(Arrays.deepToString(restoreMatrix(new int[]{14,9}, new int[]{6,9,8})));
    }

    public static int[][] restoreMatrix(int[] rowSum, int[] colSum) {
        int[][] res = new int[rowSum.length][colSum.length];
        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[i].length; j++) {
                int min = Math.min(rowSum[i], colSum[j]);
                res[i][j] = min;
                rowSum[i] -= min;
                colSum[j] -= min;
            }
        }

        return res;
    }

}
